import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

img = cv.imread('../test_datas/sudoku.png',0)
img = cv.medianBlur(img,5)

maxValue = 255
adaptiveMethod = cv.ADAPTIVE_THRESH_MEAN_C
thresholdType = cv.THRESH_BINARY
blockSize,C = 11,2

th2 =cv.adaptiveThreshold(img,maxValue, adaptiveMethod,thresholdType,blockSize,C)

titles = ['Original Image',
          'Adaptive Mean Threshold',]
images = [img,th2]
plt.figure(figsize=(15,15))
for i in range(2):
    plt.subplot(1,2,i+1),plt.imshow(images[i],'gray')
    plt.title(titles[i])
    plt.xticks([])
    plt.yticks([])

plt.show()